package com.lc.file.config.aspect;

import com.lc.file.utils.RichTextFileUtils;
import com.study.common.ano.RichText;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @description: some desc
 * @author: LChuang
 * @date: 2023/12/1 13:41
 */
@Slf4j
@Aspect
@Component
public class RichTextAspect {

    /**
     * 线程本地变量,文件id集合
     */
    private static ThreadLocal<List<String>> threadLocal = new ThreadLocal<>();

    @AfterThrowing(value = "@annotation(richText)", throwing = "e")
    public void doAfterThrowing(JoinPoint joinPoint, RichText richText, Exception e) {
        try {
            List<String> values = threadLocal.get();
            values.forEach(item->{
                RichTextFileUtils.removeText(item);
            });
        } catch (Exception e1) {
            log.error(e1.getMessage(),e1);
        }
    }

}
